package lxs.tool.liberator.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Dater {
    static final String all = "yyyy.MM.dd hh:mm:ss";
    static final String left = "yyyy.MM.dd";
    static final String right = "hh:mm:ss";
    static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat();

    public static String format(Date date) {
        simpleDateFormat.applyPattern(all);
        return simpleDateFormat.format(date);
    }

    public static String formatLeft(Date date) {
        simpleDateFormat.applyPattern(left);
        return simpleDateFormat.format(date);
    }

    public static String formatRight(Date date) {
        simpleDateFormat.applyPattern(right);
        return simpleDateFormat.format(date);
    }

    public static String getYear(Date date) {
        simpleDateFormat.applyPattern(left);
        String format = simpleDateFormat.format(date);
        return format.substring(0, 4);
    }

    public static String getMonth(Date date) {
        simpleDateFormat.applyPattern(left);
        String format = simpleDateFormat.format(date);
        return format.substring(5, 7);
    }

    public static String getDay(Date date) {
        simpleDateFormat.applyPattern(left);
        String format = simpleDateFormat.format(date);
        return format.substring(8, 10);
    }

    public static String getHours(Date date) {
        simpleDateFormat.applyPattern(right);
        String format = simpleDateFormat.format(date);
        return format.substring(0,2);
    }

    public static String getMinute(Date date) {
        simpleDateFormat.applyPattern(right);
        String format = simpleDateFormat.format(date);
        return format.substring(3,5);
    }

    public static String getSecond(Date date) {
        simpleDateFormat.applyPattern(right);
        String format = simpleDateFormat.format(date);
        return format.substring(6,8);
    }
}
